package linkedlist.leetcode_82_medium_two_pointer;

public class DeleteDuplicates {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummyNode = new ListNode(-1);
        ListNode pre = dummyNode;
        while (head != null) {
            // 进入此分支时，说明 head 与下一个节点不相同，与 pre 连接
            if (head.next == null || head.val != head.next.val) {
                pre.next = head;
                pre = pre.next;
            }
            // 跳过相同的节点
            while (head.next != null && head.val == head.next.val) {
                head = head.next;
            }
            head = head.next;
        }
        //
        pre.next = null;
        return dummyNode.next;
    }
}
